/*
 * Created by JFormDesigner on Thu Jun 27 08:31:36 CST 2024
 */

package scct.shixingyu.ui;

import scct.shixingyu.dao.UserDao;
import scct.shixingyu.model.User;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.text.Normalizer;
import java.util.List;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 * @author le
 */
public class panelUserManager extends JPanel {
    DefaultTableModel model;
    FormMain main;
    public panelUserManager(FormMain  main){
        this.main=main;

        initComponents();
        initView();
    }
    private void initView(){
        model = (DefaultTableModel) tabUser.getModel();
        model.addColumn("id");
        model.addColumn("用户名");
        model.addColumn("密码");
        model.addColumn("性别");
        model.addColumn("年龄");
        model.addColumn("手机号码");
        getTable();
    }
    private  void getTable(){
        model.setRowCount(0);
        UserDao userDao=new UserDao();
        List<User>alluser =userDao.getAllUser();
        for (User user :alluser){
            model.addRow(new Object[]{user.getId(),user.getCustomername(),user.getPassword(),user.getGender(),user.getAge(),user.getMobile()});
            
        }
    }
    private void btnAdd(ActionEvent e) {
        // TODO add your code here
        DlgUserAdd dlgUserAdd = new DlgUserAdd(main);
//        设置为模态对话框
        dlgUserAdd.setModal(true);
        dlgUserAdd.setVisible(true);
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - shii
        panel1 = new JPanel();
        button1 = new JButton();
        button2 = new JButton();
        scrollPane1 = new JScrollPane();
        tabUser = new JTable();

        //======== this ========
        setBorder ( new javax . swing. border .CompoundBorder ( new javax . swing. border .TitledBorder ( new javax . swing. border .EmptyBorder ( 0
        , 0 ,0 , 0) ,  "JFor\u006dDesi\u0067ner \u0045valu\u0061tion" , javax. swing .border . TitledBorder. CENTER ,javax . swing. border .TitledBorder . BOTTOM
        , new java. awt .Font ( "Dia\u006cog", java .awt . Font. BOLD ,12 ) ,java . awt. Color .red ) ,
         getBorder () ) );  addPropertyChangeListener( new java. beans .PropertyChangeListener ( ){ @Override public void propertyChange (java . beans. PropertyChangeEvent e
        ) { if( "bord\u0065r" .equals ( e. getPropertyName () ) )throw new RuntimeException( ) ;} } );
        setLayout(new BorderLayout());

        //======== panel1 ========
        {
            panel1.setLayout(new FlowLayout(FlowLayout.RIGHT));

            //---- button1 ----
            button1.setText("\u65b0\u589e");
            button1.addActionListener(e -> btnAdd(e));
            panel1.add(button1);

            //---- button2 ----
            button2.setText("\u4fee\u6539");
            panel1.add(button2);
        }
        add(panel1, BorderLayout.NORTH);

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(tabUser);
        }
        add(scrollPane1, BorderLayout.CENTER);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - shii
    private JPanel panel1;
    private JButton button1;
    private JButton button2;
    private JScrollPane scrollPane1;
    private JTable tabUser;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
